//
//  main.c
//  单链表
//
//  Created by 卜绎皓 on 2022/5/24.
//

#include "SList.h"

void TestSList1() {
    //头指针
    SListNode* pList = NULL;//pList永远指着第一个
    //...
    SListPushBack(&pList, 1);
    SListPushBack(&pList, 2);
    SListPushBack(&pList, 3);
    SListPushBack(&pList, 4);
    SListPushBack(&pList, 5);
    SListPushBack(&pList, 6);
    //这里要传地址，所以SList.c那边要用二级指针来接受
    SListPrint(pList);
    //打印是不需要传地址的，因为不需要改变内容，跟以前C语言学的是一样的道理

    SListPopBack(&pList);
    SListPopBack(&pList);
    SListPrint(pList);


    SListPushFront(&pList, 0);
    SListPushFront(&pList, -1);
    SListPushFront(&pList, -2);
    SListPrint(pList);

    SListPopFront(&pList);
    SListPopFront(&pList);
    SListPopFront(&pList);
    SListPrint(pList);
}
void TestSList2() {
    //头指针
    SListNode* pList = NULL;//pList永远指着第一个
    //...
    SListPushBack(&pList, 1);
    SListPushBack(&pList, 2);
    SListPushBack(&pList, 3);
    SListPushBack(&pList, 4);
    SListPushBack(&pList, 5);
    SListPushBack(&pList, 6);
    SListPrint(pList);
    //测试查找，顺便修改一下
    SListNode* pos = SListFind(pList, 3);
    if (pos) {//如果查找接口返回的不是NULL，则修改
        pos->data = 30;
    }
    SListPrint(pList);
}
int main() {
    TestSList1();
    TestSList2();
    return 0;
}


